;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages wigust-firefox)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages python)
  #:use-module (guix build-system trivial)
  #:use-module (guix download)
  #:use-module (guix packages))

(define-public firefox-openwith
  (package
    (name "firefox-openwith")
    (version "7.1")
    (source
     (origin
       (method url-fetch)
       (uri (string-append
             "https://github.com/darktrojan/openwith/archive/VERSION_"
             version ".tar.gz"))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32
         "0dr9y0kamn60k4a4j8cn9sm371ccg3mlxkh5sqdz2v4fw4y3z5d6"))))
    (build-system trivial-build-system)
    (native-inputs
     `(("tar" ,tar)
       ("gzip" ,gzip)
       ("python" ,python)))
    (arguments
     `(#:modules ((guix build utils))
       #:builder
       (begin
         (use-modules (guix build utils))
         (setenv "PATH"
                 (string-append
                  (assoc-ref %build-inputs "tar") "/bin" ":"
                  (assoc-ref %build-inputs "gzip") "/bin" ":"
                  (assoc-ref %build-inputs "python") "/bin"))
         (invoke "tar" "xvf" (assoc-ref %build-inputs "source"))
         (with-directory-excursion (string-append "openwith-VERSION_"
                                                  ,version
                                                  "/webextension/native")
           (substitute* "open_with_linux.py"
             (("#!/usr/bin/env python")
              (which "python3"))
             (("'/usr/share/applications'" line)
              (string-join (list ""
                                 line
                                 "os.path.expanduser('~/.guix-profile/share/applications')"
                                 "'/run/current-system/profile/share/applications'")
                           ", ")))
           (install-file "open_with_linux.py"
                         (string-append (assoc-ref %outputs "out")
                                        "/bin")))
         #t)))
    (home-page "https://darktrojan.github.io/openwith/")
    (synopsis "Open URLs in other programs")
    (description "This extension displays a list of your browsers on
your menus and toolbars in Firefox.  Clicking on them takes you to the
page you're looking at in the browser of your choice.")
    (license license:mpl2.0)))
